package hlhj.fhp.supreme.activitys

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import hlhj.fhp.supreme.BaseAty
import hlhj.fhp.supreme.R
import hlhj.fhp.supreme.javabean.TextBean
import hlhj.fhp.supreme.network.Urls
import hlhj.fhp.supreme.utils.JsonCallBack
import kotlinx.android.synthetic.main.activity_help_center_aty.*
import java.util.ArrayList

class HelpCenterAty : BaseAty() {
    private lateinit var adp :BaseQuickAdapter<TextBean.DataBean,BaseViewHolder>
    private val datas=ArrayList<TextBean.DataBean>()
    override fun getContentId(): Int {
        return R.layout.activity_help_center_aty
    }

    override fun initView() {

        adp=object :BaseQuickAdapter<TextBean.DataBean,BaseViewHolder>(R.layout.help_item,datas){
            override fun convert(helper: BaseViewHolder?, item: TextBean.DataBean?) {
                helper?.setText(R.id.itemTittle,"${helper!!.adapterPosition+1}.:  ${item?.post_title}")
            }
        }
        hotList.layoutManager=LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)
        hotList.adapter=adp
        /*公告*/
        OkGo.post<TextBean>(Urls.BaseUrl+ Urls.TEXT)
                .params("cid",25)
                .execute(object : JsonCallBack<TextBean>(this){
                    override fun onSuccess(response: Response<TextBean>?) {
                        val bean = response?.body()
                        if (bean?.code==1){
                            datas.addAll(bean?.data)
                            adp.notifyDataSetChanged()
                        }
                    }
                })
    }
    override fun initListener() {
        btExit.setOnClickListener {
            finish()
        }
        adp.setOnItemClickListener { adapter, view, position ->
            val intent = Intent(this, TextDetailAty::class.java)
            intent.putExtra("id",datas[position].id.toString())
            startActivity(intent)

        }
        btNoSolution.setOnClickListener {
            val intent = Intent(this, ReportAty::class.java)
            startActivity(intent)
        }
    }
}
